package pl.wroc.uni.ii.evolution.engine.operators.general.composition;

import pl.wroc.uni.ii.evolution.engine.EvPopulation;
import pl.wroc.uni.ii.evolution.engine.prototype.EvOperator;
import pl.wroc.uni.ii.evolution.engine.prototype.EvIndividual;
import pl.wroc.uni.ii.evolution.engine.prototype.EvReplacement;

/**
 * 
 * It creates a children population and using replacement operator combine it with input population.
 * 
 * 
 * @author Zbigniew Nazimek, Jarek Fuks
 */
public class EvReplacementComposition<T extends EvIndividual> implements EvOperator<T> {
  
  private EvOperator<T> children_operator;
  private EvReplacement<T> replacement;
  
  
  /**
   * Constructor.
   * @param children_operator creates children of population
   * @param replacement using input population and children creates result population  
   */
  public EvReplacementComposition(EvOperator<T> childrent_operator, EvReplacement<T> replacement) {
    this.children_operator = childrent_operator;
    this.replacement = replacement;
  }
 
  
  public EvPopulation<T> apply(EvPopulation<T> population) {
    return replacement.apply(new EvPopulation<T>(population), children_operator.apply(population));
  }

}
